<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020-06-22
  Time: 19:08
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE HTML>
<html>
<head>
    <title>制度详情</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="/lib/layui/layui/css/layui.css">
    <%--js--%>
    <script type="text/javascript" src="/js/jquery/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="/js/base/base.js" ></script>
    <script src="/lib/layui/layui/layui.js"></script>

    <style>
        html, body {
            height: 100%;
            width: 100%;
        }
        .items{
            height: 40px;
            line-height: 40px;
            font-size: 20px;
            background: #999;
            /*margin: 20px 0;*/
            background: #f2f2f2;
        }
        #PHTML a{
            color: blue;
        }
        #PHTML{
            /*height: 75vh;*/
            overflow-y: auto;
            padding: 10px;
            text-align: left;
        }
        #instsName{
            width: 100%;
            text-align: center;
            height: 60px;
            line-height: 60px;
            color: #2a588c;
            font-size: 25px;
            font-weight: bold;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
        .institutional{
            display: flex;
            flex-direction: row;
            width: 100%;
            overflow: hidden;
            height: 40px;
            background-color: #d3e7fa;
            justify-content: flex-end;
        }
        #airstar{
            display: inline-block;
            width: 40px;
            cursor: pointer;
        }
    </style>
</head>
<body>
<div class="layui-form box">
<%--    <div class="header" style="margin: 20px 10px; font-size: 20px">详情</div>--%>
    <form id="ajaxforms" action="/customer/addWorkbench" style="text-align: center">
        <div>
                    <span id="instsName"></span>

            <div style="margin-top:10px" >
                <div class="institutional">
                    <div class="layui-form-item" style="line-height: 36px">
                        <span class="layui-icon"  id="airstar" title="收藏" onclick="favorites(this)"></span>
                    </div>
                    <div class="layui-form-item" style="width: 260px">
                        <label class="layui-form-label"style="width:auto">制度编号:</label>
                        <div class="layui-input-block">
                            <input disabled id="instNumber" type="text" name="instNumber" required lay-verify="required" placeholder=""
                                   autocomplete="off" class="layui-input" style="border: 0;width: 135px;background: #d3e7fa;margin-left: -24px;">
                        </div>
                    </div>
                    <div class="layui-form-item" style="width: 260px;margin-left: -25px;">
                        <label class="layui-form-label">制度分类:</label>
                        <div class="layui-input-block">
                            <input disabled id="institutionSortName"  type="text" required lay-verify="required" placeholder=""
                                   autocomplete="off" class="layui-input" style="border: 0;width: 135px;background: #d3e7fa;">
                        </div>
                    </div>
                </div>

            <div id="FILE" class="layui-form-item">
                <label class="layui-form-label" style="font-size: 20px; width: 86px;">制度文件:</label>
                <div class="layui-input-block">
                    <ul name="fileUl" style="padding-top: 8px;">

                    </ul>
                </div>
            </div>
            <div id="HTML" class="layui-form-item">
<%--                <textarea id="demo" style="display: none;"></textarea>--%>
                <div class="layui-layedit-iframe" style="display: block; margin: 10px auto; width: 100%; ">
                    <p id="PHTML"></p>
                </div>
            </div>
        </div>
        </div>
    </form>
</div>
</div>
</body>
</html>
<script>
    var userIds
    // 获取地址栏参数值
    function getQueryString(name){
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }

    $(function(){
            $.get('/InstitutionContent/findContentById',{
                instId:getQueryString('instId')
            },function(res){
                if (res.flag){
                    let obj=res.object;
                    userIds = obj.userIds
                    if(userIds==1){
                        //实心
                        $('#airstar').addClass('layui-icon-star-fill').css('color','orange').attr('userIds','2');
                    }else{
                        //空心
                        $('#airstar').addClass('layui-icon-star').attr('userIds','1');
                    }
                    //回显
                    $('#instsName').html(obj.instName);
                    $('#instNumber').val(obj.instNumber);
                    $('#institutionSortName').val(obj.institutionSort.sortName);
                    if (obj.instType=='1'){
                        $('#instType').val("网页形式");
                        $('#FILE').hide();
                        $('#PHTML').html(obj.instContent);
                    }else{
                        $('#instType').val("文件形式");

                        $('#HTML').hide();
                        let attachmentList=obj.attachmentList;
                        let str='';
                        for (let i = 0; i < attachmentList.length; i++) {
                            str+='<li style="text-align: left;">' +
                                '<a href="/download?'+attachmentList[i].attUrl+'" style="font-size: 20px; color: #1E9FFF;">' +
                                '<i class="layui-icon layui-icon-file-b" style="font-size: 20px;"></i> ' +
                                attachmentList[i].attachName+
                                '</a> ' +
                                '</li>';
                        }
                        $('ul[name="fileUl"]').html(str);
                    }
                }
            })
        
    });


    function favorites(Ethis) {
        var userIds = $(Ethis).attr('userIds');

        $.ajax({
            url:'/InstitutionContent/editContent',
            type:'get',
            dataType:'json',
            data:{
                isEdit:"编辑",
                userIds:userIds,
                instId:getQueryString('instId')
            },
            success:function (res) {
                if (userIds == '1'){
                    $('#airstar').removeClass('layui-icon-star').addClass('layui-icon-star-fill').css('color','orange');
                    $(Ethis).attr('userIds','2');
                }else{
                    $(Ethis).attr('userIds','1');
                    $('#airstar').removeClass('layui-icon-star-fill').addClass('layui-icon-star').css('color','')

                }
            }
        })
    }

</script>
